package com.chinacoal.hr.levelimpl.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinacoal.hr.levelapi.entity.AttendanceInfoTemp;
import com.chinacoal.hr.levelimpl.mapper.AttendanceInfoTempMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author: YunTao.Li
 * @create: 2019-12-22 17:46
 * @description:
 **/
@Component
public class AttendanceInfoTempDao {
    @Resource
    private AttendanceInfoTempMapper attendanceInfoTempMapper;

    public void insertAttendanceInfoTemp(AttendanceInfoTemp record) {
        attendanceInfoTempMapper.insert(record);
    }

    public void updateAttendanceInfoTemp(AttendanceInfoTemp record) throws Throwable {
        this.attendanceInfoTempMapper.updateById(record);
    }

    public void clearAttendanceInfoTemp() throws Throwable {
        QueryWrapper queryWrapper = new QueryWrapper();
        this.attendanceInfoTempMapper.delete(queryWrapper);
    }

    /**
     * 根据条件获得list查询结果
     *
     * @param condition :
     * @return : java.util.List<com.chinacoal.hr.levelimpl.entity.AttendanceInfoTemp>
     * @author : YunTao.Li
     * @date : 2019/12/26 2019/12/26
     */
    public List<AttendanceInfoTemp> getAttendanceInfoTemps(Map<String, Object> condition) throws Throwable {
        String sessionId = condition.get("sessionId") != null ? condition.get("sessionId").toString() : "";

        QueryWrapper queryWrapper = new QueryWrapper();

        if (StringUtils.isNotBlank(sessionId)) {
            queryWrapper.eq("SESSION_ID", sessionId);
        }

        List<AttendanceInfoTemp> attendanceInfoTemps = this.attendanceInfoTempMapper.selectList(queryWrapper);
        return attendanceInfoTemps;
    }
}
